<template>
<div style="width: 100%; height: 100vh;  background: url('https://cn.bing.com/th?id=OHR.AtigunPassAurora_ZH-CN5486073819_1920x1080.jpg&rf=LaDigue_1920x1080.jpg'); overflow: hidden ">
  <div style="width: 400px; margin: 150px auto">
    <div style="color: #ccc; font-size: 30px;text-align: center; padding: 30px 0">欢迎登录</div>
    <el-form ref="form" :model="form" size="normal" :rules="rules">
      <el-form-item prop="username">
        <el-input v-model="form.username">
          <template #prefix>
<!--            icon图标-->
            <div style="font-size: 20px;">
              <UserFilled style="width: 1em; height: 1em; margin-right: 8px;" />
            </div>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input v-model="form.password" show-password>
          <template #prefix>
            <!--            icon图标-->
            <div style="font-size: 20px;">
              <Lock style="width: 1em; height: 1em; margin-right: 8px;" />
            </div>
          </template>
        </el-input>
      </el-form-item>
      <el-form-item>
      <el-button style="width: 100%" type="primary" @click="login">登录</el-button>
      </el-form-item>
      </el-form>
  </div>
</div>
</template>

<script>
import {UserFilled,Lock} from '@element-plus/icons-vue'
import {ElMessage} from "element-plus";
import request from "../utils/request";
export default {
  name: "Login",
  data() {
    return {
      form: {},
      rules: {
        username: [
          {required: true, message: '请输入用户名', trigger: 'blur'},
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
        ],
      }
    }
  },
  methods: {
    login(){
      this.$refs['form'].validate((valid) => {
        if (valid) {
        }
      })
        request.post("/user/login",this.form).then(res => {
        if(res.code === '0'){
          ElMessage({
            type:'success',
            message:'登录成功',
          })
          /*页面跳转*/
          this.$router.push("/")
        }else {
          ElMessage({
            type:'error',
            message:res.msg,
          })
        }
      })
    }
  }
  ,
  components: {
    UserFilled,
    Lock

  }
}

</script>

<style scoped>


</style>